import Router from "koa-router";
import {excel} from "../../common/utils/utils.js";
import fs from "fs";
import allowFilesUpload from "../../middleware/mid/allowFilesUpload.js";
import axios from "axios";

const router = Router({
  prefix: '/test'
})

let stations = []
router.post('/add', allowFilesUpload(true), async (ctx, next) => {
  let file = ctx.request.files.file;
  let data = excel.reader(file.filepath);
  fs.unlinkSync(file.filepath); // 删除文件
  for (let i = 0; i < data[0].data.length; i++) {
    /*let row = data[0].data[i];
    let obj = {
      alias: row[0],
      name: row[0],
      token: 'e6d91a48a35d4730bc9b5918a120b7f41',
      address: row[1],
      lat: row[3],
      lng: row[2],
      gridid: 50009,
      type: 3,
      deviceid: row[10],
      parameter_: "PM10,PM25,TSP,noise,temperature,humidity,windspeed,winddirection,pressure,SO2,CO,NO2,O3,OIL,VOC,CO2,H2S,NH3",
      brand: '瞭望环保',
      tcp_protocol: 212,
      status: 1,
    };
    let res = await axios.post('http://web.aqihj.com:8081/manage/cdevice/addDeviceAndStation', obj,{headers:{"Content-Type":"application/x-www-form-urlencoded"}});
    console.log(res);*/
  }
  ctx.body = data;
});
export default router;